package com.ltf.controller.adm;

import com.ltf.entity.Course;
import com.ltf.entity.XJson;
import com.ltf.service.CourseService;
import com.ltf.utils.PackJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//班级管理
@RestController
@RequestMapping("/api/adm/course")
public class CourseController {
    //打印输出换成这个
    private Logger logger=LoggerFactory.getLogger(this.getClass());
    @Autowired
    CourseService courseService;

    public CourseController(){}

    //显示课程
    @GetMapping("/findAll")
    public XJson findAll(){
        List<Course> courses = this.courseService.findAll();
        return PackJson.packX(200,"",courses);
    }

    //查询单个
    @PostMapping("/findOne")
    public XJson findOne(String cno){
        logger.debug(cno);
        Course course = this.courseService.findOne(cno);
        return PackJson.packX(200,"",course);
    }

    //添加
    @PostMapping("/add")
    public XJson add(Course course){
        this.courseService.add(course);
        List<Course> courses = this.courseService.findAll();
        return PackJson.packX(200,"添加成功",courses);
    }

    //修改
    @PostMapping("/update")
    public XJson update(Course course){
        this.courseService.update(course);
        List<Course> courses = this.courseService.findAll();
        return PackJson.packX(200,"修改成功",courses);
    }

    //删除
    @GetMapping("/del")
    public XJson del(String cno){
        this.courseService.del(cno);
        List<Course> courses = this.courseService.findAll();
        return PackJson.packX(200,"删除成功",courses);
    }
}
